/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.utfpr.dao;

import br.com.caelum.vraptor.ioc.Component;
import br.edu.utfpr.bean.Voo;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author guardezi
 */
@Component
public class DaoVoo {
    private final EntityManager em;

    public DaoVoo(EntityManager em) {
        this.em = em;
    }
    
    public Voo gravar(Voo v){
        em.persist(v);
        ultimo();
        return v;
    }
    
    public List lista(){
        Query q = em.createQuery("select v from Voo v");
        return q.getResultList();
    }
    

    
    
    public void ultimo(){
        Query q = em.createQuery("select v from Voo v ");
        Voo  v = null;
        
        List lista = q.getResultList();
        v=(Voo) lista.get(lista.size()-1);
        System.out.println("Codigo:"+v.getVooCodigo());
//        return v;
    }

}
